package com.example.administrator.recycleview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Adapter;
import android.widget.LinearLayout;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    RecyclerView stulist;
    final ArrayList<Student> students=new ArrayList<>();
    private RecyclerView.Adapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        stulist=findViewById(R.id.stuList);
        inntstudent();
        adapter=new StudentAdapter(MainActivity.this,students);
        stulist.setAdapter(adapter);
        LinearLayoutManager manager = new LinearLayoutManager(MainActivity.this);
        stulist.setLayoutManager(manager);
    }

    private void inntstudent() {
        Student s1=new Student(18,"张一",R.drawable.dog1);
        Student s2=new Student(18,"张二",R.drawable.dog2);
        Student s3=new Student(18,"张三",R.drawable.dog3);
        Student s4=new Student(18,"张四",R.drawable.dog4);
        Student s5=new Student(18,"张五",R.drawable.dog5);
        students.add(s1);
        students.add(s2);
        students.add(s3);
        students.add(s4);
        students.add(s5);
    }
}
